package com.boyi.cycling_master.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.alertview.AlertView;
import com.bigkoo.alertview.OnDismissListener;
import com.bigkoo.alertview.OnItemClickListener;
import com.boyi.cycling_master.R;
import com.boyi.cycling_master.application.CyclingApplication;
import com.boyi.cycling_master.common.MoT;
import com.boyi.cycling_master.common.SnackUtil;
import com.boyi.cycling_master.ui.base.BaseToolBarActivity;
import com.zhy.autolayout.AutoFrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author Lee_Mofeel
 * @version 1.0
 * @date 2017/7/26/026 14:45
 * @Description 设置界面
 */

public class SettingActivity extends BaseToolBarActivity {
    @BindView(R.id.sw_setting_message)
    Switch swSettingMessage;
    @BindView(R.id.frame_setting_message_flag)
    AutoFrameLayout frameSettingMessageFlag;
    @BindView(R.id.frame_setting_change_password)
    AutoFrameLayout frameSettingChangePassword;
    @BindView(R.id.frame_setting_bind_phone_num)
    AutoFrameLayout frameSettingBindPhoneNum;
    @BindView(R.id.frame_setting_bind_other)
    AutoFrameLayout frameSettingBindOther;
    @BindView(R.id.frame_setting_clear_cache)
    AutoFrameLayout frameSettingClearCache;
    @BindView(R.id.frame_setting_help_center)
    AutoFrameLayout frameSettingHelpCenter;
    @BindView(R.id.frame_setting_user_idea)
    AutoFrameLayout frameSettingUserIdea;
    @BindView(R.id.frame_setting_about_me)
    AutoFrameLayout frameSettingAboutMe;
    @BindView(R.id.tv_btn_setting_exit_login)
    TextView tvBtnSettingExitLogin;

    private AlertView alertViewExit, alertViewClear;

    @Override
    public int getContentViewId() {
        return R.layout.activity_setting;
    }

    @Override
    public void initLogic() {
        swSettingMessage.setChecked(CyclingApplication.getInstance().getUserInfo().getMsgStatus().equals("1")?true :false);
        swSettingMessage.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                
            }
        });
        alertViewExit = new AlertView("退出登录", "确定退出么？", "取消", new String[]{"确定"}, null, this, AlertView.Style.Alert, new OnItemClickListener() {
            @Override
            public void onItemClick(Object o, int position) {
                switch (position) {
                    case 0:
                        MoT.showShort(SettingActivity.this,"账户已退出");
                        // 清理用户
                        CyclingApplication.getInstance().getUserInfo().delete();
                        break;
                    case -1:
                        break;
                }
            }
        }).setCancelable(true).setOnDismissListener(null);
        alertViewClear = new AlertView("清理缓存", "确定清理缓存么？", "取消", new String[]{"确定"}, null, this, AlertView.Style.Alert, new OnItemClickListener() {
            @Override
            public void onItemClick(Object o, int position) {
                switch (position) {
                    case 0:
                        MoT.showShort(SettingActivity.this,"缓存已清理");
                        break;
                    case -1:
                        break;
                }
            }
        }).setCancelable(true).setOnDismissListener(null);
    }

    @Override
    public void getBundleExtras(Bundle bundle) {

    }

    @Override
    public String pageTitle() {
        return "设置";
    }


    @OnClick({R.id.frame_setting_message_flag, R.id.frame_setting_change_password, R.id.frame_setting_bind_phone_num, R.id.frame_setting_bind_other, R.id.frame_setting_clear_cache, R.id.frame_setting_help_center, R.id.frame_setting_user_idea, R.id.frame_setting_about_me, R.id.tv_btn_setting_exit_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.frame_setting_message_flag:
                break;
            case R.id.frame_setting_change_password:
                startActivity(new Intent(this, PwdChangeActivity.class));
                break;
            case R.id.frame_setting_bind_phone_num:
                startActivity(new Intent(this, PhoneChangeOldActivity.class));
                break;
            case R.id.frame_setting_bind_other:// 绑定暂不做
                break;
            case R.id.frame_setting_clear_cache:
                alertViewClear.show();
                break;
            case R.id.frame_setting_help_center:
                startActivity(new Intent(this, HelpCenterActivity.class));
                break;
            case R.id.frame_setting_user_idea:
                startActivity(new Intent(this, UserIdeaActivity.class));
                break;
            case R.id.frame_setting_about_me:
                startActivity(new Intent(this, AboutMeActivity.class));
                break;
            case R.id.tv_btn_setting_exit_login:
                alertViewExit.show();
                break;
        }
    }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            if (alertViewExit != null && alertViewExit.isShowing()) {
                alertViewExit.dismiss();
                return false;
            }
            if (alertViewClear != null && alertViewClear.isShowing()) {
                alertViewClear.dismiss();
                return false;
            }
        }
        return super.onKeyDown(keyCode, event);
    }
}
